package com.kang.service.serviceImpl;

import com.kang.mapper.OrderSubMapper;
import com.kang.pojo.Items;
import com.kang.pojo.OrderSub;
import com.kang.service.ItemsService;
import com.kang.service.ShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @Author 吃三明治派对中的康康
 * @Date 2022/5/1 11:13
 * @Version 1.0
 */

@Service
public class ShoppingServiceImpl implements ShoppingService {

    @Autowired
    OrderSubMapper orderSubMapper;
    @Autowired
    ItemsService itemsService;

    @Override
    public List<OrderSub> searchAllOrder() {
        return orderSubMapper.searchAllOrder();
    }

    @Override
    public void delShoppingByOid(String oid) {
        orderSubMapper.delByOid(oid);
    }

    @Override
    public void delShoppingById(long id) {
        orderSubMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void addShoppingByGid(long id) {
        Items item = itemsService.selectGoodsById(id);
        OrderSub orderSub = new OrderSub();
        //产生随机oid
        orderSub.setOid(UUID.randomUUID().toString().replace("-",""));
        orderSub.setId(item.getId());
        orderSub.setBuynum(1);
        orderSub.setPrice(item.getPrice());
        orderSub.setSum(orderSub.getPrice()*orderSub.getBuynum());
        orderSub.setName(item.getName());
        orderSubMapper.insert(orderSub);
    }

    @Override
    public void deleteAllShopping() {
        orderSubMapper.delAllShopping();
    }
}
